import http from "./http.js";
import globalConfig from "@/utils/config";
/**
 * 数据访问对象封装
 */
var urlEncode = function(param, key, encode) {
	if (param == null) return "";
	var paramStr = "";
	var t = typeof param;
	if (t == "string" || t == "number" || t == "boolean") {
		paramStr +=
			"&" +
			key +
			"=" +
			(encode == null || encode ? encodeURIComponent(param) : param);
	} else {
		for (var i in param) {
			var k =
				key == null ?
				i :
				key + (param instanceof Array ? "[" + i + "]" : "." + i);
			paramStr += urlEncode(param[i], k, encode);
		}
	}
	return paramStr;
};
//基础
let url = globalConfig.baseURL + "api/";
let httpType = "Sys/";
let httpUrl = url + httpType;
//业务
let urls = globalConfig.projectURL + "api/";
let httpCall = "Call/";
let httpProject = urls + httpCall;

//罪犯
let urlz = globalConfig.criminalURL + "api/";
let pass = "Pss/";
let httpCriminal = urlz + pass


const base = {
	SysCmdPropertyStatic: function(options) {
		// 码表资产统计
		return http.post(httpUrl + "SysCmdPropertyStatic", options);
	},
	sysCmdTree: function(options) {
		return http.post(httpUrl + "sysCmdTree", options);
	},
	PropertySelect: function(options) {
		return http.post(httpUrl + "PropertySelect", options);
	},

	FaceRecordCriminalByHour: function(options) {
		// 罪犯小时
		return http.post(httpProject + "FaceRecordCriminalByHour", options);
	},
	FaceRecordSelect: function(options) {
		// 点名记录
		return http.post(httpProject + "FaceRecordSelect", options);
	},
	ExceptionReportAdd: function(options) {
		// 新增上报
		return http.post(httpProject + "ExceptionReportAdd", options);
	},
	ExceptionReportUpdate: function(options) {
		// 修改上报
		return http.post(httpProject + "ExceptionReportUpdate", options);
	},
	UserCascader: function(options) {
		// 人员
		return http.post(httpUrl + "UserCascader", options);
	},
	LoginSelect: function(options) {
		// 点名记录
		return http.post(httpUrl + "LoginSelect", options);
	},
	ClockLast: function(options) {
		// 上一次上报数据
		return http.post(httpCriminal + "ClockLast", options);
	},
	ZdbUpdate: function(options) {
		// 修改值班
		return http.post(urls + "Es/" + "ZdbUpdate", options);
	},
	ZdbAdd: function(options) {
		//新增值班
		return http.post(urls + "Es/" + "ZdbAdd", options);
	},
	OrgSelect: function(options) {
		// 点名记录
		return http.post(url + 'sys/' + "OrgSelect", options);
	},

	//今日刑满
	CriminalZr: function(options) {
		return http.post(httpCriminal + "CriminalZr", options);
	},
	//码表
	sysCmdTree: function(options) {
		return http.post(httpUrl + "sysCmdTree", options);
	},
	sysCmdUpdate: function(options) {
		return http.post(httpUrl + "SysCmdUpdate", options);
	},
	SysCmdAdd: function(options) {
		// 
		return http.post(httpUrl + "SysCmdAdd", options);
	},

};
const users = {
	BaseInfo: function(options) { // 登录人信息 
		return http.post(httpUrl + "BaseInfo", options);
	},

	UserInfoSelect: function(options) { // 台账
		return http.post(httpUrl + "UserInfoSelect", options);
	},
}
//罪犯
const zfpt = {
	CriminalNumCount: function(options) {
		return http.post(httpCriminal + "CriminalNumCount", options);
	},
	CriminalAdd: function(options) {
		return http.post(httpCriminal + "CriminalAdd", options);
	},
	CriminalDel: function(options) {
		return http.post(httpCriminal + "CriminalDel", options);
	},
	CriminalInOutSelect: function(options) {
		//重点罪犯查询
		return http.post(httpCriminal + "CriminalInOutSelect", options);
	},
	CriminalMainSelect: function(options) {
		//重点罪犯查询
		return http.post(httpCriminal + "CriminalMainSelect", options);
	},
	CriminalMainSelect: function(options) {
		//重点罪犯查询
		return http.post(httpCriminal + "CriminalMainSelect", options);
	},
	CyLevelSelect: function(options) { // 处遇等级-列表
		return http.post(httpCriminal + "CyLevelSelect", options);
	},
	NightSearchStatic: function(options) {
		// 夜巡数量
		return http.post(httpCriminal + "NightSearchStatic", options);
	},
	CriminalInfoSelect: function(options) { // 罪犯详情
		return http.post(httpCriminal + "CriminalInfoSelect", options);
	},
	NightSearchSelect: function(options) {
		// 查询夜巡
		return http.post(httpCriminal + "NightSearchSelect", options);
	},
	CriminalSelectHome: function(options) {
		// 罪犯人员数据
		return http.post(httpCriminal + "CriminalSelectHome", options);
	},

	CyLevelStatic: function(options) {
		// 处遇等级
		return http.post(httpCriminal + "CyLevelStatic", options);
	},
	CriminalLdAdd: function(options) {
		// 漏点记录
		return http.post(httpCriminal + "CriminalLdAdd", options);
	},
	ClockReportLdAdd: function(options) {
		// 点名记录新增
		return http.post(httpCriminal + "ClockReportLdAdd", options);
	},
	ClockLdLast: function(options) {
		// 点名记录查询
		return http.post(httpCriminal + "ClockLdLast", options);
	},

	CriminalStateCount: function(options) {
		// 状态数据列表
		return http.post(httpCriminal + "CriminalStateCount", options);
	},




	ClockReportAdd: function(options) {
		// 整点上报新增
		return http.post(httpCriminal + "ClockReportAdd", options);
	},
	ClockLast: function(options) {
		// 整点上次的数据
		return http.post(httpCriminal + "ClockLast", options);
	},
	ClockReportStatic: function(options) {
		// 整点上次的数据
		return http.post(httpCriminal + "ClockReportStatic", options);
	},
	CriminalSelect: function(options) {
		// 罪犯人员
		return http.post(httpCriminal + "CriminalSelect", options);
	},
	CriminalStateAdd: function(options) {
		// 切换状态
		return http.post(httpCriminal + "CriminalStateAdd", options);
	},
	CriminalStateSelect: function(options) {
		//罪犯状态查询
		return http.post(httpCriminal + "CriminalStateSelect", options);
	},
}
//智能警务
const znjw = {
	ClockPoliceStatic: function(options) {
		//统计
		return http.post(urls + "Es/" + "ClockPoliceStatic", options);
	},
	ShiftLogSelect: function(options) {
		//异常情况
		return http.post(urls + "Es/" + "ShiftLogSelect", options);
	},
	ExceptionReportDel: function(options) {
		//异常情况
		return http.post(httpProject + "ExceptionReportDel", options);
	},
	ZhzxDailySelect: function(options) {
		//异常情况
		return http.post(httpProject + "ZhzxDailySelect", options);
	},
	ZhzxDailyAdd: function(options) {
		//异常情况
		return http.post(httpProject + "ZhzxDailyAdd", options);
	},
	ZhzxDailyUpdate: function(options) {
		//异常情况
		return http.post(httpProject + "ZhzxDailyUpdate", options);
	},
	ShiftDutyUpdate: function(options) {
		// 修改交接班
		return http.post(httpProject + "ShiftDutyUpdate", options);
	},
	ShiftDutyUpdate: function(options) {
		// 修改交接班
		return http.post(httpProject + "ShiftDutyUpdate", options);
	},
	ShiftDutyAdd: function(options) {
		// 新增交接班
		return http.post(httpProject + "ShiftDutyAdd", options);
	},
	ShiftDutySelect: function(options) {
		// 交接班查询
		return http.post(httpProject + "ShiftDutySelect", options);
	},
	FaceRecordCriminalByHour: function(options) {
		// 查询用户（小时内去重）
		return http.post(httpProject + "FaceRecordCriminalByHour", options);
	},
	ShiftSelect: function(options) {
		// 班次查询
		return http.post(urls + "Es/" + "ShiftSelect", options);
	},
	ShiftQuery: function(options) {
		// 班次查询
		return http.post(urls + "Es/" + "ShiftQuery", options);
	},
	// CriminalZr: function (options) {
	//   // 今日刑满
	//   return http.post(urls + "cmpJ/" + "CriminalZr", options);
	// },
	ZdbSelect: function(options) {
		// 值班查询
		return http.post(urls + "Es/" + "ZdbSelect", options);
	},
	CriminalZr: function(options) {
		// 今日刑满
		return http.post(httpCriminal + "CriminalZr", options);
	},
	CriminalStatic: function(options) {
		// 罪犯分布
		return http.post(httpCriminal + "CriminalStatic", options);
	},
	CriminalStateStatic: function(options) {
		// 罪犯状态
		return http.post(httpCriminal + "CriminalStateStatic", options);
	},
	ExceptionReportSelect: function(options) {
		//异常情况
		return http.post(httpProject + "ExceptionReportSelect", options);
	},

	WorkReportSelect: function(options) {
		//重点罪犯查询
		return http.post(httpProject + "WorkReportSelect", options);
	},

	UserStatic: function(options) {
		//警力分布
		return http.post(httpUrl + "UserStatic", options);
	}
}


const cmd = {
	//码表
	sysCmdTree: function(options) {
		// 
		return http.post(httpUrl + "sysCmdTree", options);
	},
	//码表
	SysCmdByType: function(options) {
		// 
		return http.post(httpUrl + "SysCmdByType", options);
	},
	sysCmdUpdate: function(options) {
		// 
		return http.post(httpUrl + "SysCmdUpdate", options);
	},
	SysCmdAdd: function(options) {
		// 
		return http.post(httpUrl + "SysCmdAdd", options);
	},
	SysCmdDel: function(options) {
		//码表删除
		return http.post(httpUrl + "SysCmdDel", options);
	},
};
const news = {};
const org = {};


const API = {
	base: base,
	znjw,
	news: news,
	org,
	zfpt,
	users,
	cmd,
	commonQuery: function(url, options) {
		return new Promise((resolve, reject) => {
			http.post(httpUrl + url + "Select", options).then(
				(res) => {
					resolve(res);
				},
				function(error) {
					reject(error);
				}
			);
		});
	},
	commonHandle: function(url, options) {
		return new Promise((resolve, reject) => {
			http.post(httpUrl + url, options).then(
				(res) => {
					resolve(res);
				},
				function(error) {
					reject(error);
				}
			);
		});
	},
	saveResource: function(options) {
		// 保存上传一般文件
		(http.defaults.headers.post["Content-Type"] =
			"multipart/form-data;charset=UTF-8"),
		(http.defaults.headers.post["token"] = sessionStorage.getItem("token"));
		return http.post(url + "File/FileUpload", options, {
			transformRequest: [
				function(data, headers) {
					const formData = new FormData();
					for (const key of Object.keys(data)) {
						formData.append(key, data[key]);
					}
					return formData;
				},
			],
		});
	},
	saveResourceNew: function(options) {
		// 保存上传一般文件
		(http.defaults.headers.post["Content-Type"] =
			"multipart/form-data;charset=UTF-8"),
		(http.defaults.headers.post["token"] = sessionStorage.getItem("token"));
		return http.post(url + "File/FileUploadNew", options, {
			transformRequest: [
				function(data, headers) {
					const formData = new FormData();
					for (const key of Object.keys(data)) {
						formData.append(key, data[key]);
					}
					return formData;
				},
			],
		});
	},
	uploadExcel: function(options) {
		//excel数据表导入
		(http.defaults.headers.post["Content-Type"] =
			"multipart/form-data;charset=UTF-8"),
		(http.defaults.headers.post["token"] = sessionStorage.getItem("token"));
		return http.post(url + "File/ExcelUpload", options, {
			transformRequest: [
				function(data, headers) {
					const formData = new FormData();
					for (const key of Object.keys(data)) {
						formData.append(key, data[key]);
					}
					return formData;
				},
			],
		});
	},
	diyCommonHandle: function(apiurl, options) {
		return new Promise((resolve, reject) => {
			http.post(url + apiurl, options).then(
				(res) => {
					resolve(res);
				},
				function(error) {
					reject(error);
				}
			);
		});
	},
	// 登录
	login: function(options) {
		//登录
		return http.post(httpUrl + "Login", options);
	},
	TokenLogin: function(options) {
		//token登录
		return http.post(httpUrl + "TokenLogin", options);
	},
	logout: function(options) {
		//退出登录
		return http.post(httpUrl + "Logout", options);
	},


	changePassword: function(options) {
		//修改密码
		return http.post(httpUrl + "ChangePassword", options);
	},
};
export default API;